# Maintainer: Cameron Banta <cbanta@gmail.com>
# Contributor: Jeff Bilyk <jbilyk@gmail.com>
# Contributor: Bartłomiej Piotrowski <nospam@bpiotrowski.pl>
# Contributor: Dennis Przytarski <dennis@przytarski.com>
pkgname=tengine
pkgver=2.3.3
pkgrel=2
pkgdesc="Lightweight HTTP and reverse proxy server. It is based on the Nginx HTTP server"
url="https://tengine.taobao.org/"
arch="all !aarch64"
license="BSD-2-Clause"
pkgusers="tengine"
pkggroups="tengine www-data"
options="!check" # Makefile test cmd does not work
replaces="nginx"
makedepends="linux-headers gd-dev geoip-dev libxml2-dev libxslt-dev
	openssl-dev pcre-dev perl-dev pkgconf zlib-dev"
install="$pkgname.pre-install $pkgname.pre-upgrade"
subpackages="$pkgname-doc $pkgname-openrc"
source="http://tengine.taobao.org/download/tengine-$pkgver.tar.gz
	tengine.initd
	tengine.logrotate
	"

build() {
	./configure \
		--prefix=/var/lib/$pkgname \
		--sbin-path=/usr/sbin/$pkgname \
		--conf-path=/etc/$pkgname/$pkgname.conf \
		--pid-path=/run/$pkgname/$pkgname.pid \
		--lock-path=/run/$pkgname/$pkgname.lock \
		--http-client-body-temp-path=/var/tmp/$pkgname/client_body \
		--http-proxy-temp-path=/var/tmp/$pkgname/proxy \
		--http-fastcgi-temp-path=/var/tmp/$pkgname/fastcgi \
		--http-uwsgi-temp-path=/var/tmp/$pkgname/uwsgi \
		--http-scgi-temp-path=/var/tmp/$pkgname/scgi \
		--with-perl_modules_path=/usr/lib/perl5/vendor_perl \
		--user=$pkgusers \
		--group=${pkggroups%% *} \
		--with-file-aio \
		--with-http_addition_module \
		--with-http_auth_request_module \
		--with-http_dav_module \
		--with-http_degradation_module \
		--with-http_flv_module \
		--with-http_geoip_module \
		--with-http_gunzip_module \
		--with-http_gzip_static_module \
		--with-http_image_filter_module \
		--with-http_mp4_module \
		--with-http_random_index_module \
		--with-http_realip_module \
		--with-http_secure_link_module \
		--with-http_slice_module \
		--with-http_ssl_module \
		--with-http_stub_status_module \
		--with-http_sub_module \
		--with-http_perl_module \
		--with-http_v2_module \
		--with-http_xslt_module \
		--with-ipv6 \
		--with-mail \
		--with-mail_ssl_module \
		--with-pcre-jit \
		--with-threads

	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname

	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
	install -Dm644 README.markdown "$pkgdir"/usr/share/doc/$pkgname/README
}

sha512sums="
077ef6dbbb122002f02655e470a7a38a0c5adfe6135faa5c10dce2c38d6327aee12f0248b22862b9989557cdff4981bb7004e702431525b8f591ec87c3fcd46c  tengine-2.3.3.tar.gz
3075188f052bf67b4079e78a8b0c56ede7cd8cee890031bf970e45fe8ebdc5739ef092de691108d78b8a111a07cfc98e7ff30234f6a8583db3c647e5fea7d109  tengine.initd
b0ad2fffe47210805ba09667dc40b09d30c7d1ff19fcb0fd4aa548355dcb992a2f9a7a9d3b0992a81e20eecbe37a91c3646b56324daf356c1d811e526fe663f3  tengine.logrotate
"
